#include "gtest/gtest.h"
#include <iostream>
#include <sstream>
#include <acapella/serialize/serialize.h>


TEST(SerializeTest, CompileTest)
{
    int test_int = 1;
    size_t test_size_t = 2;
    unsigned int test_uint = 3;
    const unsigned int test_cuint = 4;
    
    std::ostringstream oss;
    acapella::serialize::serializer<std::ostream> so(oss);
    so << test_int << test_size_t << test_uint << test_cuint;
    EXPECT_EQ(so.good(), true);

    
    std::istringstream iss(oss.str());
    acapella::serialize::serializer<std::istream> si(iss);
    unsigned int result_uint;
    si >> test_int >> test_size_t >> test_uint >> result_uint;

    EXPECT_EQ(1, test_int);
    EXPECT_EQ((size_t)2, test_size_t);
    EXPECT_EQ((unsigned int)3, test_uint);
    EXPECT_EQ((unsigned int)4, result_uint);
}

TEST(SerializeTest, StringTest)
{
    std::string i = "123";
    
    std::ostringstream oss;
    acapella::serialize::serializer<std::ostream> so(oss);
    EXPECT_EQ(true, so.write(i));

    
    std::istringstream iss(oss.str());
    acapella::serialize::serializer<std::istream> si(iss);
    EXPECT_EQ(true, si.read(i));

    EXPECT_EQ("123", i);
}

TEST(SerializeTest, VectorTest)
{
    std::vector<std::string> testVec;
    testVec.push_back("123");
    testVec.push_back("456");
    
    std::ostringstream oss;
    acapella::serialize::serializer<std::ostream> so(oss);
    EXPECT_EQ(true, so.write(testVec));

    
    std::istringstream iss(oss.str());
    acapella::serialize::serializer<std::istream> si(iss);
    EXPECT_EQ(true, si.read(testVec));

    EXPECT_EQ("123", testVec[0]);
    EXPECT_EQ("456", testVec[1]);
}


TEST(SerializeTest, MapTest)
{
    std::map<std::string, std::string> testMap;
    testMap["123"] = "123";
    testMap["345"] = "345";
    
    std::ostringstream oss;
    acapella::serialize::serializer<std::ostream> so(oss);
    EXPECT_EQ(true, so.write(testMap));

    
    std::istringstream iss(oss.str());
    acapella::serialize::serializer<std::istream> si(iss);
    EXPECT_EQ(true, si.read(testMap));

    EXPECT_EQ("123", testMap["123"]);
    EXPECT_EQ("345", testMap["345"]);
}
